﻿#include "Shape.h"
#include <QList>
#include <QtMath>

Shape::Shape()
{

}

Shape::Shape(const QVector<VPoint> &points, double radius):
    radius(radius)
{
    arrangement(points);
}

Shape::~Shape()
{

}

//获取多边形所有端点信息
const QVector<VPoint> &Shape::getPoints() const
{
    return this->points;
}

//获取半径信息
double Shape::getRadius() const
{
    return this->radius;
}

//重设半径
void Shape::setRadius(double radius)
{
    this->radius = radius;
}

//对点进行排序,可以的话之后取消
//参数points经过排序后，赋值到此对象的成员points
void Shape::arrangement(QVector<VPoint> points)
{
    QList<VPoint> points_temp;
    foreach (VPoint po, points)
    {
        points_temp.prepend(po);
        int i = 1;

        //判断是否到达队尾,再判断是否需要换位
        while(i < points_temp.length() && points_temp.at(i - 1).angle() < points_temp.at(i).angle())
        {
            points_temp.swap(i - 1, i);
            ++i;
        }
    }

    foreach(VPoint po, points_temp)
    {
        this->points.append(po);
    }
}
